package com.chang.dp.utils;

import java.util.Random;

public class StringUtil {
    /**
     * 获取一定长度的随机字符串
     * @param length
     * @return
     */
    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(i == 0 ? 52 : 62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 获取一个长度为32的随机id
     * @return
     */
    public static String getRandomString() {
        return getRandomString(32);
    }
}
